package se.webbzon.boltzmann.editor.propertyframe;

import java.util.Collection;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JColorChooser;
import javax.swing.JPanel;

import se.webbzon.boltzmann.editor.mvc.EditorModel;
import se.webbzon.oschi01.worldobject.WorldStaticObject;
import se.webbzon.oschi01.worldobject.appearance.LightAppearance3D;

public abstract class StaticLightPropertyFrame extends WorldStaticObjectPropertyFrame {

	// The color input for this property frame
	private final JColorChooser	colorInput;
	
	/*============================================================
	Constructors
	============================================================*/
	
	/** Creates a new static light property frame. **/
	public StaticLightPropertyFrame(EditorModel model, WorldStaticObject instance) {
		super(model, instance);
		
		LightAppearance3D appearance3d = 
				(LightAppearance3D) instance.getAppearance();
		
		JPanel panel = new JPanel();
		panel.setLayout(new BoxLayout(panel,BoxLayout.Y_AXIS));
		
		JPanel colorPanel = new JPanel();
		colorPanel.setBorder(BorderFactory.createTitledBorder("Color"));
		colorInput = new JColorChooser(appearance3d.getColor());
		colorPanel.add(colorInput);
		panel.add(colorPanel);
		
		addPanel("Light",panel);
	}
	
	/*============================================================
	Public Methods
	============================================================*/
	
	@Override public boolean apply(Collection<String> errorMessages) {
		if (super.apply(errorMessages)) {
			WorldStaticObject instance = (WorldStaticObject) getInstance();
			LightAppearance3D appearance3d = 
					(LightAppearance3D) instance.getAppearance();
			appearance3d.setColor(colorInput.getColor());
			return true;
		} else
			return false;
	}

}
